package com.example.demo.controller;

import com.example.demo.searcher.DocSearcher;
import com.example.demo.searcher.Result;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DocSearcherController {
    private static DocSearcher docSearcher=new DocSearcher();
    private ObjectMapper objectMapper=new ObjectMapper();
    @RequestMapping(value = "/searcher",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String searcher(@RequestParam("query") String query) throws JsonProcessingException {
        List<Result> results=docSearcher.search(query);
        return objectMapper.writeValueAsString(results);
    }

}
